// 下拉菜单管理器 - 确保同一时间只有一个下拉菜单打开
type DropdownCallback = (currentId: string) => void;

class DropdownManager {
  private listeners: Set<DropdownCallback>;

  constructor() {
    this.listeners = new Set();
  }

  // 注册监听器
  subscribe(callback: DropdownCallback): () => void {
    this.listeners.add(callback);
    return () => this.listeners.delete(callback);
  }

  // 通知所有监听器关闭，除了当前打开的
  notifyOpen(currentId: string): void {
    this.listeners.forEach(listener => listener(currentId));
  }
}

export const dropdownManager = new DropdownManager();
